﻿using BLL;
using Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using YunProject.Controllers.Base;

namespace YunProject.Controllers
{
    /// <summary>
    /// 汇总统计
    /// </summary>
    public class SummaryController : BaseController
    {
       SummaryBLL sumBLL;
        ChartBLL chartBLL;

        public SummaryController()
        {
            sumBLL =new SummaryBLL();
            chartBLL =new ChartBLL();
        }
        [Authorize]
        public IActionResult PlanRate()
        {
            return View();
        }
        [Authorize]
        public IActionResult PlanCost()
        {
            return View();
        }
        [Authorize]
        public IActionResult PlanCostDetail()
        {
            return View();
        }
        [Authorize]
        public IActionResult DataShow()
        {
            return View();
        }
        [Authorize]
        public IActionResult BarStockInfo()
        {
            return View();
        }
        [Authorize]
        public IActionResult BarStockDetail()
        {
            return View();
        }
        [Authorize]
        public IActionResult BarTraceability()
        {
            return View();
        }
        [Authorize]
        public IActionResult GongXuTotal()
        {
            return View();
        }
        [Authorize]
        public IActionResult StockKy()
        {
            return View();
        }
        [HttpPost]
        public JsonResult PlanStatusTotal()
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl = sumBLL.PlanStatusTotal();
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult SaleOrderProductTotal(string condition,string dataCount)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl = chartBLL.SaleOrderProductTotal(condition, userObj["baseCode"].ToString(),dataCount);
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult SaleOrderTotal(string condition, string dataCount)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl = chartBLL.SaleOrderTotal(condition, userObj["baseCode"].ToString(), dataCount);
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult GongXuFinishCount( string dataCount)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl = chartBLL.GongXuFinishCount(dataCount);
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult ChengPinNeedIn(string dataCount)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl = chartBLL.ChengPinNeedIn(dataCount);
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult BarTree(string datas)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl =sumBLL.BarTrackTree(datas);
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult GongXuMachine(string gxCode)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                BasicBLL basicBLL = new BasicBLL();
                rsl = basicBLL.GetGongXuMachine(gxCode);
            }
            return Json(rsl);
        }
        
        [HttpGet]
        public JsonResult getDataList(string page, string limit, string condition, string dataType)
        {
            var rsl = new ReturnResult();
       
            string pageCount = "1";
            string msg = "";
            var datas = new object();
            var userObj = LoginInfo();
            if (dataType == "prl")
            {
                rsl = sumBLL.PlanRateList(page, limit, ref pageCount, condition);//生产计划执行进度
            }
            else if (dataType == "pcl")
            {
                rsl = sumBLL.PlanCostList(page, limit, ref pageCount, condition);//生产计划成本
            }
            else if (dataType == "pcd")
            {
                rsl = sumBLL.PlanCostDetails(page, limit, ref pageCount, condition);//生产计划成本明细
            }
            else if (dataType == "bstl")
            {

                rsl = sumBLL.GetBarStockList(page, limit, condition, userObj["baseCode"].ToString(), ref pageCount);//条码存货库存
            }
            else if (dataType == "bsil")
            {
                rsl = sumBLL.GetInHouseBarInfo(page, limit, ref pageCount, condition);//条码存货库存
            }
            else if (dataType == "btrac")
            {
                rsl = sumBLL.BarInfoTrack(condition);
            }
            else if (dataType == "proky")
            {
                rsl = sumBLL.ProductStock(condition, userObj["baseCode"].ToString());
            }
            else if (dataType == "gxtp")
            {
                rsl = sumBLL.GetGongXuTotalData(condition);
            }
            


            if (rsl.Result)
            {
                datas = rsl.Data;
            }
            else
            {
                msg = rsl.Message;
            }

            var Data = new
            {
                count = pageCount,
                msg = msg,
                code = "0",
                data = datas
            };

            return new JsonResult(Data);
        }
    }
}
